﻿@model   Inovout.Cloud.Applications.Security.Models.ApplicationUser

<div class="w-1">
    <div class="wgt">
        <div class="w-1-6">
            @Html.Partial("_Navigation", (object)ViewBag.Project)
        </div>
        <div class="w-5-6">
            <div class="wgt">
                <div class="w20 oauth_describe">
                    <h3>OAuth</h3>
                    <div>OAuth2.0允许用户与您共享特定的数据（例如，联系人列表），当拥有保持他们的用户名，密码和其他私人信息。</div>
                    <div>
                        <a data-click-command="page.showDialog('@Url.Action("Create", "OAuthCredential", new { projectId = HttpContext.Current.Request.QueryString["projectId"].ToString() })',600,650,'创建Oauth Key').done('credentialList.insertNewRow(data)')">创建ClientID</a>
                    </div>
                </div>
                <div class="dataList w40" id="credentialList" data-discriminator="_Type">
                    <div class="wgt template" data-template_id="WebApplicationCredential">
                        <div class="w-1 header">Client ID for web application</div>
                        <div class="w-1-3 leftDesc">ClientID:</div>
                        <div class="w-2-3 rightContent">{{:ClientId}}</div>
                        <div class="w-1-3 leftDesc">Screct:</div>
                        <div class="w-2-3 rightContent">
                            @{
                                var clientId_template = "label{{:ClientId}}";
                                var callback_template = clientId_template.ToString() + ".html(data)";
                                <label id="@clientId_template">{{:ClientSecret}}</label>
                                <a data-click-command="page.post('@Url.Action("UpdateClientSecret", "WebApplicationCredential")','{\'WebApplicationCredentialId\':\'{{:Id}}\'}','@callback_template')">重置</a>  

                            }
                        </div>
                        <div class="w-1-3 leftDesc">URL:</div>
                        <div class="w-2-3 rightContent">{{:RedirectUris}}</div>
                        <div class="w-1-3 leftDesc">JS源:</div>
                        <div class="w-2-3 rightContent">{{:JavascriptOrigins}}</div>
                        <div class="w-1 footer"></div>
                        <div class="handle">
                            @{
                                var editUrl = Url.Action("Edit", "WebApplicationCredential");
                                var deleteUrl = Url.Action("Delete", "WebApplicationCredential");
                                <a data-click-command="page.showDialog('@editUrl/{{:Id}}?projectId=@HttpContext.Current.Request.QueryString["projectId"].ToString()',600,650,'修改Oauth Key').done('page.reload()')">修改</a>
                                <a href='@deleteUrl/{{:Id}}?projectId=@HttpContext.Current.Request.QueryString["projectId"].ToString()'>删除</a>
                            }
                        </div>
                    </div>
                    <div class="wgt template" data-template_id="NativeApplicationCredential">
                        <div class="w-1 header">Service Account</div>
                        <div class="w-1-3 leftDesc">ClientID:</div>
                        <div class="w-2-3 rightContent">{{:ClientId}}</div>
                        <div class="w-1-3 leftDesc">Screct:</div>
                        <div class="w-2-3 rightContent">{{:ClientSecret}}</div>
                        <div class="w-1 footer"></div>
                    </div>

                    @foreach (var item in Model.OAuthCredentials)
                    {
                        if (@item.GetType().ToString().IndexOf("NativeApplicationCredential") != -1)
                        {
                            var nativeApplicationCredential = (Inovout.Cloud.Applications.Security.Models.NativeApplicationCredential)@item;
                        <div class="wgt">
                            <div class="w-1 header">Service Account</div>
                            <div class="w-1-3 leftDesc">ClientID:</div>
                            <div class="w-2-3 rightContent">@item.ClientId</div>
                            <div class="w-1-3 leftDesc">Screct:</div>
                            <div class="w-2-3 rightContent">@nativeApplicationCredential.ClientSecret</div>
                            <div class="w-1 footer"></div>
                        </div>
                        }
                        else
                        {
                            var webApplicationCredential = (Inovout.Cloud.Applications.Security.Models.WebApplicationCredential)@item;
                            var clientId = @webApplicationCredential.ClientId;
                            clientId = "label" + clientId.ToString();
                            var callback = clientId.ToString() + ".html(data)";
                        <div class="wgt">
                            <div class="w-1 header">Client ID for web application</div>
                            <div class="w-1-3 leftDesc">ClientID:</div>
                            <div class="w-2-3 rightContent">@webApplicationCredential.ClientId</div>
                            <div class="w-1-3 leftDesc">Screct:</div>
                            <div class="w-2-3 rightContent">
                                <label id="@clientId">@webApplicationCredential.ClientSecret</label>
                                <a data-click-command="page.post('@Url.Action("UpdateClientSecret", "WebApplicationCredential")','{\'WebApplicationCredentialId\':\'@webApplicationCredential.Id\'}','@callback')">重置</a>
                            </div>
                            <div class="w-1-3 leftDesc">URL:</div>
                            <div class="w-2-3 rightContent">@webApplicationCredential.RedirectUris</div>
                            <div class="w-1-3 leftDesc">JS源:</div>
                            <div class="w-2-3 rightContent">@webApplicationCredential.JavascriptOrigins</div>
                            <div class="w-1 footer"></div>
                            <div class="handle">
                                <a data-click-command="page.showDialog('@Url.Action("Edit", "WebApplicationCredential", new { Id = @webApplicationCredential.Id, projectId = HttpContext.Current.Request.QueryString["projectId"].ToString() })',600,650,'修改Oauth Key').done('page.reload()')">修改</a>
                                <a href="@Url.Action("Delete", "WebApplicationCredential", new { id = @webApplicationCredential.Id, projectId = HttpContext.Current.Request.QueryString["projectId"].ToString() })">删除</a>
                            </div>
                        </div>
                        
                        }
                    }
                </div>
            </div>
            <div class="wgt">
                <div class="w20 publickey_describe">
                    <h3>Public API access</h3>
                    <div>
                        使用此键的不需要任何用户操作或不同意的，不授予访问任何帐户信息，并且不用于授权
                    </div>
                    <div>
                        <a data-click-command="page.showDialog('@Url.Action("Create", "PublicApiAccessCredential", new { projectId = HttpContext.Current.Request.QueryString["projectId"].ToString() })',600,500).done('page.showDialog(data,600,500).done(\'publicKeyList.insertNewRow(data)\')')">创建KEY</a>
                    </div>
                </div>
                <div class="dataList w40" id="publicKeyList" data-discriminator="_Type">
                    <div class="wgt template" data-template_id="ServerApplicationCredential">
                        <div class="w-1 header">互联网应用 Key</div>
                        <div class="w-1-3 leftDesc">API key:</div>
                        <div class="w-2-3 rightContent">
                            {{:ApiKey}}
                             @{
                                 var apiKey_template = "label{{:ApiKey}}";
                                 var callback_apikey_template = apiKey_template.ToString() + ".html(data)";
                                 <label id="@apiKey_template">{{:ClientSecret}}</label>
                                 <a data-click-command="page.post('@Url.Action("UpdateApiKey", "ServerApplicationCredential")','{\'ServerApplicationCredentialId\':\'{{:Id}}\'}','@callback_apikey_template')">重置</a>
                             }
                        </div>
                        <div class="w-1-3 leftDesc">IPs:</div>
                        <div class="w-2-3 rightContent">{{:IPs}}</div>
                        <div class="w-1-3 leftDesc">创建日期:</div>
                        <div class="w-2-3 rightContent">{{:CreatedTime}}</div>
                        <div class="w-1 footer"></div>
                        <div class="handle">
                            @{
                                var apikey_EditUrl = Url.Action("Edit", "ServerApplicationCredential");
                                var apikey_DeleteUrl = Url.Action("Delete", "ServerApplicationCredential");
                                <a data-click-command="page.showDialog('@apikey_EditUrl/{{:Id}}?projectId=@HttpContext.Current.Request.QueryString["projectId"].ToString()',600,650,'修改Oauth Key').done('page.reload()')">修改</a>
                                <a href='@apikey_DeleteUrl/{{:Id}}?projectId=@HttpContext.Current.Request.QueryString["projectId"].ToString()'>删除</a>
                            }
                        </div>
                    </div>
                    <div class="wgt template" data-template_id="BrowserApplicationCredential">
                        <div class="w-1 header">本地应用 Key</div>
                        <div class="w-1-3 leftDesc">API key:</div>
                        <div class="w-2-3 rightContent">{{:ApiKey}}</div>
                        <div class="w-1-3 leftDesc">Referers:</div>
                        <div class="w-2-3 rightContent">{{:Referers}}</div>
                        <div class="w-1-3 leftDesc">创建日期:</div>
                        <div class="w-2-3 rightContent">{{:CreatedTime}}</div>
                        <div class="w-1 footer"></div>
                    </div>
                    @foreach (var item in Model.PublicApiAccessCredentials)
                    {
                        if (@item != null && @item.GetType().ToString().IndexOf("ServerApplicationCredential") != -1)
                        {
                            var serverApplicationCredential = (Inovout.Cloud.Applications.Security.Models.ServerApplicationCredential)@item;
                            var apiKey = "label" + @serverApplicationCredential.ApiKey;
                            var callback_apikey = apiKey.ToString() + ".html(data)";
                        <div class="wgt">
                            <div class="w-1 header">Key for server applications</div>
                            <div class="w-1-3 leftDesc">API key:</div>
                            <div class="w-2-3 rightContent">
                                <label id="@apiKey">@serverApplicationCredential.ApiKey</label>
                                <a data-click-command="page.post('@Url.Action("UpdateApiKey", "ServerApplicationCredential")','{\'ServerApplicationCredentialId\':\'@serverApplicationCredential.Id\'}','@callback_apikey')">重置</a>
                            </div>
                            <div class="w-1-3 leftDesc">IPs:</div>
                            <div class="w-2-3 rightContent">@serverApplicationCredential.IPs</div>
                            <div class="w-1-3 leftDesc">创建日期:</div>                      
                            <div class="w-2-3 rightContent">@serverApplicationCredential.CreatedTime</div>                      
                            <div class="w-1 footer"></div>
                            <div class="handle">
                                <a data-click-command="page.showDialog('@Url.Action("Edit", "ServerApplicationCredential", new { Id = @serverApplicationCredential.Id, projectId = HttpContext.Current.Request.QueryString["projectId"].ToString() })',600,650,'修改Oauth Key').done('page.reload()')">修改</a>
                                <a href="@Url.Action("Delete", "ServerApplicationCredential", new { id = @serverApplicationCredential.Id, projectId = HttpContext.Current.Request.QueryString["projectId"].ToString() })">删除</a>
                            </div>
                        </div>
                        }
                        else
                        {
                            var browserApplicationCredential = (Inovout.Cloud.Applications.Security.Models.BrowserApplicationCredential)@item;
                        <div class="wgt">
                            <div class="w-1 header">Key for browser applications</div>
                            <div class="w-1-3 leftDesc">API key:</div>
                            <div class="w-2-3 rightContent">@browserApplicationCredential.ApiKey</div>
                            <div class="w-1-3 leftDesc">Referers:</div>
                            <div class="w-2-3 rightContent">@browserApplicationCredential.Referers</div>
                            <div class="w-1-3 leftDesc">创建日期:</div>
                            <div class="w-2-3 rightContent">@browserApplicationCredential.CreatedTime.ToShortDateString()</div>
                            <div class="w-1 footer"></div>
                        </div>
                        }

                    }
                </div>
            </div>
        </div>
    </div>
</div>
